package com.flower.core_service.controller;


import com.flower.core_service.object.entity.AuthRole;
import com.flower.core_service.object.request.RoleMenuRequest;
import com.flower.core_service.service.AuthRoleService;
import com.common.baseModel.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 角色控制类
 */
@RestController
@Slf4j
@RequestMapping("/coreService/system/role")
public class AuthRoleController {

    @Autowired
    AuthRoleService authRoleService;

    /**
     * 添加角色
     * @param role 角色实体
     * @return
     */
    @PostMapping("/addRoles")
    public JsonResult<Objects> addRoles(@RequestBody AuthRole role){
        log.info(role.toString());
        authRoleService.save(role);
        return  JsonResult.isOk();
    }

    /**
     * 获取所有角色
     * @return
     */
    @GetMapping("/getAllRoles")
    public JsonResult<List<AuthRole>> getAllRoles() {
        List<AuthRole> roles= authRoleService.findAllRoles();
        //List<AuthRole> r= authRoleService.list(null);
        log.info(roles.toString());
        return JsonResult.create(roles);
    }

    /**
     * 跟新权限
     * @param model 角色权限模型
     * @return
     */
    @PostMapping("/updateRole")
    public JsonResult<Object> updateRole(@RequestBody RoleMenuRequest model)
    {
        log.info(model.toString());

        authRoleService.updateRole(model);
        return JsonResult.isOk();
    }

}

    